var reloadShare;
var shareData;
var shareDatas = {
    title : "全新速派 顷刻倾城",
    desc : "立体主义美学 唤醒感官",
    imgurl : 'http://autoshow.skoda.com.cn/2015/chengdu/mobile/images/share.jpg',
    linkurl: 'http://autoshow.skoda.com.cn/2015/chengdu/mobile/mobile.html'
};
function setShareData() {

    //分享到朋友圈
    wx.onMenuShareTimeline({
        title: shareDatas.title,
        desc: shareDatas.title,
        link: shareDatas.linkurl,
        imgUrl: shareDatas.imgurl,
        trigger: function (res) {
            // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容，因为客户端分享操作是一个同步操作，这时候使用ajax的回包会还没有返回
        },
        success: function (res) {
        },
        cancel: function (res) {
            // 用户取消分享后执行的回调函数
        },
        fail: function (res) {
            //alert(JSON.stringify(res));
        }
    });

    //发送给朋友
    wx.onMenuShareAppMessage({
        title: shareDatas.title,
        desc: shareDatas.desc,
        link: shareDatas.linkurl,
        imgUrl: shareDatas.imgurl,
        type: "",
        dataUrl: "",
        success: function () {
        },
        trigger: function (res) {
            // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容，因为客户端分享操作是一个同步操作，这时候使用ajax的回包会还没有返回
        },
        cancel: function () {
            // 用户取消分享后执行的回调函数
        },
        fail: function (res) {
            //alert(JSON.stringify(res));
        }
    });
}

wx.ready(function () {
     shareData = {
         title: shareDatas.title,
         desc: shareDatas.desc,
         link: shareDatas.linkurl,
         imgUrl: shareDatas.imgurl,
         success: function () {
         },
         cancel: function () {
         }
     };
     wx.hideMenuItems({
         menuList: [
             'menuItem:share:qq',
             'menuItem:share:weiboApp',
             'menuItem:favorite',
             'menuItem:share:facebook',
             'menuItem:copyUrl',
             'menuItem:readMode',
             'menuItem:openWithQQBrowser',
             'menuItem:openWithSafari',
             'menuItem:share:email',
             'menuItem:share:QZone'
         ]
     });
    setShareData();
    reloadShare();


    //document.querySelector('#previewImage').onclick = function () {
    //    var imgList = [
    //        'http://autoshow.skoda.com.cn/2015/chengdu3/mobile/images/bg1.jpg',
    //        'http://autoshow.skoda.com.cn/2015/chengdu3/mobile/images/pg1_map_img1.png'
    //     ];
    //    wx.previewImage({
    //        current: "http://autoshow.skoda.com.cn/2015/chengdu3/mobile/images/pg1_title.png",
    //        urls:  imgList
    //    });
    //};

 });
function reloadShare()
{
    wx.onMenuShareTimeline(shareData);
    wx.onMenuShareAppMessage(shareData);
    setShareData();
}
function getOAuth(resp)
{

    wx.config({
        debug: false,
        appId: resp.appId,
        timestamp: resp.timestamp,
        nonceStr: resp.nonceStr,
        signature: resp.signature,
        jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ", "onMenuShareWeibo",'hideOptionMenu','hideMenuItems']
    });

    wx.error(function (res) {
         // alert(res);
    });
}
$.ajax({
    type: "get",
    url: "http://autoshow.skoda.com.cn/2015/chengdu/api/index.php?auth/ticket&" + (new Date()).getTime(),
    dataType: 'json',
    async:true,
    data:{url:window.location.href},
    success: function (data) {
        getOAuth(data);
    },
    error: function (xhr, ajaxOptions, thrownError) {
        //alert("Http status: " + xhr.status + " " + xhr.statusText + "\najaxOptions: " + ajaxOptions + "\nthrownError:" + thrownError + "\n" + xhr.responseText);
    }
});
